﻿module Sustainalytics.Notifications.Admin {

    export class NotificationsStatusesService implements INotificationsStatusesService {

        private items: NotificationStatus[];
        private $q: ng.IQService;

        public statuses = {
            Published: { id: 1, name: 'Published' },
            Unpublished: { id: 2, name: 'Unpublished' }
        };

        constructor($q: ng.IQService) {
            this.$q = $q;

            // create items
            this.items =
            [
                { id: 1, name: 'Published' },
                { id: 2, name: 'Unpublished' },
            ];
        }

        // get Notification status by ID
        public getNotificationStatus(id: number): ng.IPromise<NotificationStatus> {
            var def: ng.IDeferred<NotificationStatus> = this.$q.defer();

            var item: NotificationStatus = null;
            $(this.items).each(function () {
                if (this.id == id) {
                    item = this;
                    return false;
                }
            });

            def.resolve(item);

            return def.promise;
        }

        // get notifications types
        public getNotificationsStatuses(): ng.IPromise<NotificationStatus[]> {
            var def: ng.IDeferred<NotificationStatus[]> = this.$q.defer();
            def.resolve(this.items);
            return def.promise;
        }
    }


    // register service with Notifications Angular module
    var mod = angular.module(notificationsAdminModuleName);

    mod.service('NotificationsStatusesService',
        ['$q', NotificationsStatusesService]);
}